package com.etone.smartAudit.controller;

import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.dto.adminMenu.AdminMenuDTO;
import com.etone.smartAudit.service.AdminMenuService;
import com.etone.smartAudit.vo.menu.MenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author: 蒋学伟
 * @create: 2020-06-10 09:35:06
 * @Description AdminMenuController
 */
@AllArgsConstructor
@RestController
@Api(tags = "菜单管理", value = "AdminMenuController")
public class AdminMenuController {
    private AdminMenuService adminMenuService;

    @ApiOperation(value = "获取所有菜单《完》")
    @GetMapping("/menus/all")
    public List<MenuVO> findAdminRoles(
    ) {
        return adminMenuService.findAllMenus();
    }


    @ApiOperation(value = "获取角色菜单树")
    @GetMapping("/menus/tree/{roleId}")
    public List<MenuVO> findMenusTree(@ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "roleId 角色Id", required = true) @PathVariable Integer roleId
    ) {
        return adminMenuService.findMenusTree(roleId,admin);
    }

    @ApiOperation(value = "获取角色菜单树")
    @GetMapping("/menus/treeV2/{roleId}")
    public List<MenuVO> findMenusTreeV2(@ApiIgnore @LoginAdmin Admin admin,
                                      @ApiParam(value = "roleId 角色Id", required = true) @PathVariable Integer roleId
    ) {
        return adminMenuService.findMenusTreeV2(roleId,admin);
    }


    @ApiOperation(value = "增加菜单《完》")
    @PostMapping("/menus")
    public void add(
            @ApiParam(value = "菜单表单") @RequestBody AdminMenuDTO adminMenuDTO
    ) {
        adminMenuService.save(null, adminMenuDTO);
    }

    @ApiOperation(value = "编辑菜单《完》")
    @PutMapping("/menus/{id}")
    public void add(
            @ApiParam(value = "id") @PathVariable Integer id,
            @ApiParam(value = "菜单表单") @RequestBody AdminMenuDTO adminMenuDTO
    ) {
        adminMenuService.save(id, adminMenuDTO);
    }

    @ApiOperation(value = "菜单详情《完》")
    @GetMapping("/menus/{id}")
    public MenuVO detail(
            @ApiParam(value = "id") @PathVariable Integer id
    ) {
        return adminMenuService.detail(id);
    }

    @ApiOperation(value = "删除菜单《完》")
    @DeleteMapping("/menus/{id}")
    public void delete(
            @ApiParam(value = "id") @PathVariable Integer id
    ) {
        adminMenuService.delete(id);
    }
}
